const data = Array.from(Array(2),(v,i)=>{
    return{
        account:"uaa" + i+1,
        level:Math.ceil(Math.random()*10),
        id:new Date().valueOf()+i
    }
})
/**
 * @description 获取数据
 * @param {object} params
 * @param {String} params.account 账号名
 * @returns {Array<object>}
 */
export function getDataApi(params){
    const {account} = params
    if(!account){
        return [...data]
    }else{
        return [...data.filter(item=>item.account.includes(account))]
    }
}

/**
 * @description 新增一个账号
 * @param   {object} params
 * @param   {String} params.account 账号名
 * @param   {string} params.level 账号等级
 * @returns {undefined} 无返回
 * 
 */
export function addAccountApi(params){
    const {account,level} = params
    data.push({account,level,id:new Date().valueOf()})
}


export function deteleAccountApi(params){

    const {id}  = params
    let delIndex = -1
    data.array.forEach((item,index) => {
        if(item.id===id){
            delIndex = index
        }
    })
    if(delIndex!=-1){
        data.splice(delIndex,1)
    }
}

export function updateAccountApi(params){
    const {account,level,index} = params
    let updateIndex = -1
    data.forEach((item,index)=>{
        if(item.id === id){
            updateIndex = index
        }
    })
    if(updateIndex!=-1){
        data.splice(updateIndex,1,{account,level,id})
    }
}